//
//  YZDiseaseTypeViewModel.m
//  名医通
//
//  Created by WGP on 16/5/4.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "YZDiseaseTypeViewModel.h"
#import "YZNetWorkTool.h"
#import "YZDiseaseTypeModel.h"
#import "YZComplicationModel.h"
#import "YZDoctorModel.h"

@implementation YZDiseaseTypeViewModel

+(void)loadDiseaseTypeWith:(NSInteger)ci1_id finished:(void(^)(NSArray *array,NSError *error))finished
{
    NSString *URL = @"http://iosapi.itcast.cn/doctor/searchCI3List.json.php";
    NSDictionary *parameters =
    @{
      @"page":@1,@"page_size":@15,@"ci1_id":@(ci1_id),@"keyword":@""
      };
    
    [[YZNetWorkTool sharedNetWorkTool] POST:URL parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *responseObj = (NSDictionary *)responseObject;
        NSArray *array = responseObj[@"data"];
        
        NSArray *arr = [YZDiseaseTypeModel arrayWithDicts:array].copy;
        
        finished(arr,nil);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        finished(nil,error);
    }];
}

+(void)loadComplicationWith:(NSInteger)ci1_id ci2_id:(NSInteger)ci2_id finished:(void(^)(NSArray *array,NSError *error))finished
{
    /*http://iosapi.itcast.cn/doctor/complicationList.json.php
     请求参数:{"page":1,"page_size":15,"ci1_id":1,"ci2_id":3}*/
    
    NSString *URL = @"http://iosapi.itcast.cn/doctor/complicationList.json.php";
    NSDictionary *dict = @{
     @"page":@1, @"page_size":@15,@"ci1_id":@(ci1_id),@"ci2_id":@(ci2_id)
     };
    
    [[YZNetWorkTool sharedNetWorkTool] POST:URL parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *responseObj = (NSDictionary *)responseObject;
        NSArray *array = responseObj[@"data"];
        
        if (![array isKindOfClass:[NSNull class]]) {
            NSArray *arr = [YZComplicationModel arrayWithDicts:array].copy;
            
            finished(arr,nil);
            return ;
        }
        finished([NSArray array],nil);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        finished(nil,error);
    }];
}

+(void)loadDoctorsfinished:(void(^)(NSArray *array,NSError *error))finished
{
   /* 请求地址: http://iosapi.itcast.cn/doctor/matchDoctors.json.php
    请求参数:
    {"ci1_id":1,"ci2_id":3,"ci3_id":3,"diagnosis_type":0,"page_size":15,"is_confirmed":1,"user_id":1000089, "page":1,"has_diagnosis":2}
    */
    
    NSString *URL = @"http://iosapi.itcast.cn/doctor/matchDoctors.json.php";
    NSDictionary *dicts = @{
@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"page_size":@15,@"is_confirmed":@1,@"user_id":@1000089, @"page":@1,@"has_diagnosis":@2
                            };
    [[YZNetWorkTool sharedNetWorkTool] POST:URL parameters:dicts progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *responseObj = (NSDictionary *)responseObject;
        NSArray *array = responseObj[@"data"];

        if (![array isKindOfClass:[NSNull class]]) {
            NSArray *arr = [YZDoctorModel arrayWithDicts:array].copy;

            finished(arr,nil);
            return ;
        }
        finished([NSArray array],nil);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        finished(nil,error);
    }];
}

+(void)loadMoreDatafinished:(void(^)(NSArray *array,NSError *error))finished
{
    
}

@end










